<%@ page contentType="text/html; charset=utf-8" language="java"%>
<!DOCTYPE html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
	<%@include file="/static/common/header.jsp"%>
	<%@include file="/static/common/easyui.jsp"%>
	<%@include file="/static/common/common.jsp"%>
	<link href="${ctx}/static/css/main.css" rel="stylesheet">

<script>  

$(document).ready(function(){
	
	$('#busiTable').datagrid({
		title:'工单列表信息',
		iconCls:'icon-bumen',
		method:'post',
		width:665,
		height:450,
		nowrap: false,
		striped: true,
		collapsible:false,
		url: '${ctx}/infobird/call/busilist?orderType=1',
		idField:'id',
		columns:[[
					{field:'orderType',title:'工单类型',align:'center',width:120,hidden:true,
						formatter:function(value){
							if(value==""||value==null){
								return "";
							} else if(value=="1") {
								return "话务工单";
							} else if(value=="2") {
								return "结算工单";
							} else {
								return "";
							}
						}
					},
					{field:'orderNo',title:'工单编号',align:'left',width:120},
					{field:'businessFlow',title:'业务类型',align:'left',width:300},
					{field:'remark',title:'备注',align:'left',width:120},
					{field:'status',title:'处理状态',align:'center',width:120,hidden:true,
						formatter:function(value){
							if(value==""||value==null){
								return "处理中";
							} else if(value=="0") {
								return "处理中";
							} else if(value=="1") {
								return "已退回";
							} else if(value=="2") {
								return "已处理";
							}
						}
					},
					{field:'acctNo',title:'交易账号',align:'center',width:100},
					{field:'createUser',title:'创建者',align:'center',width:120},
					{field:'createTime',title:'创建时间',align:'center',width:100, formatter:formatterdate},
					{field:'dealUser',title:'处理者',align:'center',width:120},
					{field:'dealTime',title:'处理时间',align:'center',width:100, formatter:formatterdate},
					{field:'dealFlag',title:'是否已处理',align:'center',width:80,
						formatter:function(value){
							if(value==""||value==null){
								return "否";
							} else if(value=="Y") {
								return "是";
							} else if(value=="N") {
								return "否";
							}
						}
					},
					{field:'id',title:'操作',width:160,rowspan:2,formatter:function(value, row, index){
						var oper = '<a href="#" class="viewcls" onClick="dealOrder(\''+row.id+'\', \''+row.orderType+'\', \'VIEW\')">[ 查看 ]</a>';
						if(row.dealFlag=='N'){
							oper += '<a href="#" class="dealcls" onClick="dealOrder(\''+row.id+'\', \''+row.orderType+'\', \'DEAL\')">[ 处理 ]</a>';
						}
						return oper;
					}},
				]],
				pagination:true,
				pageSize:10,
				rownumbers:true,
				
				toolbar:'#tb',
				onLoadSuccess:function(){
					$('.viewcls').linkbutton({text:'查看',plain:true,iconCls:'icon-view'}); 
					$('.dealcls').linkbutton({text:'处理',plain:true,iconCls:'icon-edit'}); 
					$('#callOrderTable').datagrid('clearSelections'); //一定要加上这一句，要不然datagrid会记住之前的选择状态，删除时会出问题
				}
			});
	});


	function formatterdate(val, row) {
		if (val != null) {
			var date = new Date(val);
			var mon = date.getMonth() + 1;
			var time = date.getDate();
			var hour = date.getHours();
			var minute = date.getMinutes();
			var second = date.getSeconds();
			if(mon<10) {
				mon = '0' + mon;
			}
			if(time<10) {
				time = '0' + time;
			}
			if(hour<10) {
				hour = '0' + hour;
			}
			if(minute<10) {
				minute = '0' + minute;
			}
			if(second<10) {
				second = '0' + second;
			}
			return date.getFullYear() + '-' + mon + '-' + time + ' ' + hour + ':' + minute + ':' + second;
		}
	}

	//表格查询
	function searchData() {
		var params = $('#busiTable').datagrid('options').queryParams; //先取得 datagrid 的查询参数
		var fields = $('#queryForm').serializeArray(); //自动序列化表单元素为JSON对象

		var orderNo = $("#orderNo").val();
		var parentBusinessId = $("#parentBusinessId").combobox('getValue');
		var dealFlag = $("#dealFlag").combobox('getValue');
		
		var cust_name = $("#cust_name").val();
		var acct_no = $("#acct_no").val();
		var mobile = $("#mobile").val();
		var telephone = $("#telephone").val();
		
		var create_user = $("#create_user").val();
		var deal_user = $("#deal_user").val();
		var start_time = $("#start_time").datetimebox("getText");
		var end_time = $("#end_time").datetimebox("getText");
		
		
		params['orderNo']=orderNo;
		params['parentBusinessId']=parentBusinessId;
		params['dealFlag']=dealFlag;
		params['cust.name']=cust_name;
		params['cust.acctNo']=acct_no;
		params['cust.mobile']=mobile;
		params['cust.telephone']=telephone;
		
		params['createUser']=create_user;
		params['dealUser']=deal_user;
		params['tempVar']=start_time;
		params['props']=end_time;

		$('#busiTable').datagrid('reload'); //设置好查询参数 reload 一下就可以了
	}
	
	function exportData() {
		var params = $('#busiTable').datagrid('options').queryParams; //先取得 datagrid 的查询参数
		var fields = $('#queryForm').serializeArray(); //自动序列化表单元素为JSON对象

		var orderNo = $("#orderNo").val();
		var parentBusinessId = $("#parentBusinessId").combobox('getValue');
		var dealFlag = $("#dealFlag").combobox('getValue');
		
		var cust_name = $("#cust_name").val();
		var acct_no = $("#acct_no").val();
		var mobile = $("#mobile").val();
		var telephone = $("#telephone").val();
		
		var create_user = $("#create_user").val();
		var deal_user = $("#deal_user").val();
		var start_time = $("#start_time").datetimebox("getText");
		var end_time = $("#end_time").datetimebox("getText");
		
		
		params['orderNo']=orderNo;
		params['parentBusinessId']=parentBusinessId;
		params['dealFlag']=dealFlag;
		params['cust.name']=cust_name;
		params['cust.acctNo']=acct_no;
		params['cust.mobile']=mobile;
		params['cust.telephone']=telephone;
		
		params['createUser']=create_user;
		params['dealUser']=deal_user;
		params['tempVar']=start_time;
		params['props']=end_time;
		
		document.getElementById("queryForm").action="${ctx}/infobird/call/exportBusiList";
		
		document.getElementById("queryForm").submit();
	}
	
	//清空查询条件
	function clearForm() {
		$('#queryForm').form('clear');
		$('#parentBusinessId').combobox('select', '0');
		searchData();
	}
	
	function dealOrder(orderId, orderType, opt) {
		if(orderType=='1') {
			dealVoiceOrder(orderId, opt);
		}
		if(orderType=='2') {
			openWin('处理结算工单', '${ctx}/infobird/call/addWin?orderId=' + orderId + '&opt=' + opt + 
					'&stmp=' + (new Date()).getTime());
		}
	}
	
	function dealVoiceOrder(orderId, opt) {
		var url = '${ctx}/infobird/call/viewHis?id=' + orderId + '&opt=' + opt +
		'&stmp=' + (new Date()).getTime();
		var returnValue = window.showModalDialog(url, window,"dialogWidth=1200px;dialogHeight=500px");
		if(returnValue=='Y') {
			$('#callOrderTable').datagrid('reload'); //设置好查询参数 reload 一下就可以了
		}
	}
</script>

<style type="text/css">

</style>
  </head>
  
<body>
	<div class="easyui-layout" data-options="fit:true">
		<div region="center" style="padding: 1px;">
				<table class="easyui-datagrid" id="busiTable" title="Basic DataGrid"  data-options="fit:true">
				</table>
		</div>
	</div>

	
    <div id="tb" class="datagrid-toolbar" style="padding:5px;height:auto">

        <div style="margin-bottom:5px">
        	<form id="queryForm" method="post">
        		<div>
        			<table id="orderQueryTable" class="listTable" cellspacing="0" cellpadding="0" border="0" style="table-layout: auto; width: 100%" data-options="fit:true">
  						<tr>
  							<td align="right">工单编号：</td>
  							<td>
								<input type="text" id="orderNo" name="orderNo" class="normal-text" style="width:150px;border-color:#95B8E7"></input>
							</td>
  							<td align="right">业务类型：</td>
  							<td>
								<select name="parentBusinessId" id="parentBusinessId" class="easyui-combobox" style="width: 150px;">
									<option value="0">=== 所有 ===</option>
									<c:forEach items="${voiceList}" var="dic">
										<option value="${dic.id}">${dic.dicName}</option>
									</c:forEach>
								</select>
							</td>
							<td align="right">是否已处理：</td>
  							<td colspan="3">
								<select name="dealFlag" id="dealFlag" class="easyui-combobox" style="width: 150px;">
									<option value="">=== 所有 ===</option>
									<c:forEach items="${dealFlagList}" var="dic">
										<option value="${dic[0]}">${dic[2]}</option>
									</c:forEach>
								</select>
							</td>
						</tr>
  						<tr>
  							<td align="right">客户姓名：</td>
  							<td>
								<input type="text" id="cust_name" name="cust_name" class="normal-text" style="width:150px;border-color:#95B8E7"></input>
							</td>
  							<td align="right">交易商账号：</td>
  							<td>
								<input type="text" id="acct_no" name="acct_no" class="normal-text" style="width:150px;border-color:#95B8E7"></input>
							</td>
  							<td align="right">手机号码：</td>
  							<td>
								<input type="text" id="mobile" name="mobile" class="normal-text" style="width:150px;border-color:#95B8E7"></input>
							</td>
  							<td align="right">固定电话：</td>
  							<td>
								<input type="text" id="telephone" name="telephone" class="normal-text" style="width:150px;border-color:#95B8E7"></input>
							</td>
						</tr>
  						<tr>
  							<td align="right">创建者：</td>
  							<td>
								<input type="text" id="create_user" name="create_user" class="normal-text" style="width:150px;border-color:#95B8E7"></input>
							</td>
  							<td align="right">处理者：</td>
  							<td>
								<input type="text" id="deal_user" name="deal_user" class="normal-text" style="width:150px;border-color:#95B8E7"></input>
							</td>
  							<td align="right">创建时间：</td>
  							<td colspan="3">
								<input type="text" id="start_time" name="start_time" class="easyui-datetimebox" style="width:150px;border-color:#95B8E7"></input>
								&nbsp;&nbsp;-&nbsp;&nbsp;
								<input type="text" id="end_time" name="end_time" class="easyui-datetimebox" style="width:150px;border-color:#95B8E7"></input>
							</td>
						</tr>
        			</table>
        		</div>
        	</form>
        </div>
        <div>
        	<table width="100%" border="0" cellpadding="0" cellspacing="0">
        		<tr>
        			<td>
        				<shiro:hasPermission name="____AgentAdmin">
        				<a href="javascript:void(0)" onclick="exportData();" class="easyui-linkbutton" iconCls="icon-search">导出</a>
        				</shiro:hasPermission>
        				<span style="float:right;margin-bottom:5px;">
        					<a href="javascript:void(0)" onclick="searchData();" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
            				<a href="javascript:void(0)" onclick="clearForm();" class="easyui-linkbutton" iconCls="icon-reload">清空</a>
        				</span>
        			</td>
        		</tr>
        	</table>
         </div>
    </div>
    
    <div id="innerFramWindow" class="easyui-window" data-options="closed:true,modal:true,collapsible:false,minimizable:false,maximizable:false,draggable:true,onBeforeClose:function(){}" style="overflow: hidden">
  		<iframe id="innerWinFram" scrolling="yes" frameborder="0"  src='' style="width:100%;height:100%;"></iframe>
	</div>

	<div id="MyPopWindow" modal="true" shadow="false" minimizable="false" cache="false" maximizable="false" collapsible="false" resizable="false" style="margin: 0px;padding: 0px;overflow: auto;"></div>
  </body>
</html>
